#include "view_others.h"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font/num_font.h"
#include "view_others_device_info.h"
#include "view_common.h"
#include "view_others_stopwatch.h"
#include "Motor.h"
#include "view.h"
#include "time/view_times.h"
#include "sports_mode.h"
#include "app_trace.h"
#include "language_text.h"
#include "device_type.h"
#define LOG(fmt, ...) app_trace_log(fmt "\r\n", ##__VA_ARGS__)
void view_others_app_url_display(void)
{
    // int x = 31;
    // int y = 31;
    // _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_9405_QRcode_29_30);
    // x += 37;
    // y += 155;
    // if (disp_ctrl.com_data.uint8_temp[100])
    // {
    //     y -= 1;
    //     disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    // }
    // else
    // {
    //     _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_9405_QRcode_29_30_37_155);
    // }
    if (disp_ctrl.loop_cnt == 0)
    {
        disp_ctrl.com_data.i_temp[0] = get_device_type();
        disp_ctrl.auto_refresh_time = 1000;
    }
    if (disp_ctrl.com_data.i_temp[0] == device_type_read)
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, 0, 0, FILE_IMG_Read_DownloadUrl);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, 0, 0, FILE_IMG_Hard_DownloadUrl);
    }

    show_button_up();
    // show_button_right();
    show_button_down();
}
void view_others_base_display(void)
{
#ifdef CUSTOM_UI
    int const temp_index_start = 50;
    int custom_ui_index = 0;
    for (int i = 0; i < OTHERS_BACK_COUNT; i++)
    {
        disp_show_resource_with_x_y(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_resource_key_others_back_start + i, temp_index_start + custom_ui_index, -1, -1);
        ++custom_ui_index;
    }
#if OTHERS_GIF_COUNT > 0
    disp_show_resource_with_x_y(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_resource_key_others_gif_start + disp_ctrl.auto_refresh_count % HEART_RATE_GIF_COUNT,
                                temp_index_start + custom_ui_index, -1, -1);
    ++custom_ui_index;
#endif
    int x = 87;
    int y = 182;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0 + custom_ui_index, x, y, FILE_IMG_9002_other_text);
    }
    // bool ret = disp_show_localize(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_string_key_others_text, temp_index_start + custom_ui_index);
    // if (!ret)
    // {
    //     _disp_show_flash_img(DISP_LFS_FILE_INDEX_0 + custom_ui_index, 87, 182, FILE_IMG_9002_other_text);
    // }
    ++custom_ui_index;

#else
    int x = 63;
    int y = 47;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_9001_other_icon);
    x = 87;
    y = 182;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_9002_other_text);
    }
    show_button_up();
    show_button_right();
    show_button_down();
#endif
}
void view_others_camera_display(void)
{
#ifdef CUSTOM_UI
    int const temp_index_start = 50;
    int custom_ui_index = 0;
    for (int i = 0; i < CAMERA_BACK_COUNT; i++)
    {
        disp_show_resource_with_x_y(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_resource_key_camera_back_start + i, temp_index_start + custom_ui_index, -1, -1);
        ++custom_ui_index;
    }
#if CAMERA_GIF_COUNT > 0
    disp_show_resource_with_x_y(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_resource_key_camera_gif_start + disp_ctrl.auto_refresh_count % HEART_RATE_GIF_COUNT,
                                temp_index_start + custom_ui_index, -1, -1);
    ++custom_ui_index;
#endif
    // x = 75;
    // y = 182;
    int x = 75;
    int y = 182;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0 + custom_ui_index, x, y, FILE_IMG_9102_camera_text);
    }
    // bool ret = disp_show_localize(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_string_key_camera_text, temp_index_start + custom_ui_index);
    // if (!ret)
    // {
    //     _disp_show_flash_img(DISP_LFS_FILE_INDEX_0 + custom_ui_index, 76, 177, FILE_IMG_3002_main_text);
    // }
    ++custom_ui_index;

#else
    int x = 58;
    int y = 36;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_9101_camera_icon);
    x = 75;
    y = 182;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_9102_camera_text);
    }
    show_button_up();
    show_button_right();
    show_button_down();
#endif
}
void view_others_camera_shake_display(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        bool connect = ble_if_connected();
        disp_ctrl.com_data.i_temp[1] = battery_ctrl_get_level(battery_ctrl_get_percent());
        disp_ctrl.com_data.i_temp[2] = battery_ctrl_if_charging();
        disp_ctrl.auto_refresh_time = 500;
        disp_ctrl.auto_close_delay = 1000;
        if (!connect && disp_ctrl.com_data.i_temp[0] != connect)
        {
            motor_start(100);
            disp_ctrl.auto_refresh_count = 0;
            disp_ctrl.auto_refresh_time = 0;
        }
        disp_ctrl.com_data.i_temp[0] = connect;
        if (connect)
        {
            display_set_update_area(58, 54, 130, 105);
        }
        else
        {
            disp_ctrl.area_update_flag = 0;
        }
    }
    if (!disp_ctrl.com_data.i_temp[0])
    {
        if (disp_ctrl.auto_refresh_count > 6)
        {
            display_show(view_others_camera, DISP_MODE_NORMAL);
            return;
        }
        int x = 60;
        int y = 36;
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_prompt_not_connect_60_36);
        x = 51;
        y = 164;
        if (disp_ctrl.com_data.uint8_temp[150])
        {
            y -= 5;
            disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[151]), 0);
        }
        else
        {
            _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_prompt_not_connect_51_164);
        }
        return;
    }
    int x = 88;
    int y = 7;
    if (disp_ctrl.com_data.i_temp[0])
    {
        disp_draw_user_image(x, y, bmp_1101_connect);
    }
    else
    {
        disp_draw_user_image(x, y, bmp_1102_noconnect);
    }
    x = 123;
    y = 9;
    uint8_t battery_level = disp_ctrl.com_data.i_temp[1];
    if (disp_ctrl.com_data.i_temp[2])
    {
        disp_ctrl.auto_refresh_time = 500;
        battery_level = disp_ctrl.auto_refresh_count % 5;
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_1103_electricity_100 + 4 - battery_level);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_1103_electricity_100 + 4 - battery_level);
    }
    const img_gif_com_t img_cfg = {
        .gif_count = 2,
        .img[0].x = 58,
        .img[0].y = 54,
        .img[0].sn = FILE_IMG_9104_camera_icon_2,
        .img[1].x = 58,
        .img[1].y = 54,
        .img[1].sn = FILE_IMG_9105_camera_icon_3,
    };
    _disp_show_flash_img_gif_all(&img_cfg, DISP_LFS_FILE_INDEX_0);
    if (disp_ctrl.auto_refresh_count > 4)
    {
        display_show(view_others_camera_static, DISP_MODE_NORMAL);
    }
    x = 32;
    y = 183;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 1;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_9106_camera_shake);
    }
}
void view_others_camera_static_display(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        bool connect = ble_if_connected();
        disp_ctrl.com_data.i_temp[1] = battery_ctrl_get_level(battery_ctrl_get_percent());
        disp_ctrl.com_data.i_temp[2] = battery_ctrl_if_charging();
        disp_ctrl.auto_refresh_time = 1000;
        disp_ctrl.auto_close_delay = 2000;
        if (!connect && disp_ctrl.com_data.i_temp[0] != connect)
        {
            motor_start(100);
            disp_ctrl.auto_refresh_count = 0;
        }
        disp_ctrl.com_data.i_temp[0] = connect;
        if (disp_ctrl.auto_refresh_count > 5)
        {
            display_show(view_others_camera, DISP_MODE_NORMAL);
            return;
        }
    }
    if (!disp_ctrl.com_data.i_temp[0])
    {
        if (disp_ctrl.auto_refresh_count > 3)
        {
            display_show(view_others_camera, DISP_MODE_NORMAL);
            return;
        }
        int x = 60;
        int y = 36;
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_prompt_not_connect_60_36);
        x = 51;
        y = 164;
        if (disp_ctrl.com_data.uint8_temp[150])
        {
            y -= 5;
            disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[151]), 0);
        }
        else
        {
            _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_prompt_not_connect_51_164);
        }
        return;
    }
    int x = 88;
    int y = 7;
    if (disp_ctrl.com_data.i_temp[0])
    {
        disp_draw_user_image(x, y, bmp_1101_connect);
    }
    else
    {
        disp_draw_user_image(x, y, bmp_1102_noconnect);
    }
    x = 123;
    y = 9;
    uint8_t battery_level = disp_ctrl.com_data.i_temp[1];
    if (disp_ctrl.com_data.i_temp[2])
    {
        disp_ctrl.auto_refresh_time = 500;
        battery_level = disp_ctrl.auto_refresh_count % 5;
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_1103_electricity_100 + 4 - battery_level);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_1103_electricity_100 + 4 - battery_level);
    }
    x = 58;
    y = 54;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_9103_camera_icon_1);
    x = 32;
    y = 183;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 1;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_9106_camera_shake);
    }
}

void view_others_power_off_display(void)
{
#ifdef CUSTOM_UI
    int const temp_index_start = 50;
    int custom_ui_index = 0;

    for (int i = 0; i < POWER_OFF_BACK_COUNT; i++)
    {
        disp_show_resource_with_x_y(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_resource_key_power_off_back_start + i, temp_index_start + custom_ui_index, -1, -1);
        ++custom_ui_index;
    }
#if POWER_OFF_GIF_COUNT > 0
    disp_show_resource_with_x_y(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_resource_key_power_off_gif_start + disp_ctrl.auto_refresh_count % HEART_RATE_GIF_COUNT,
                                temp_index_start + custom_ui_index, -1, -1);
    ++custom_ui_index;
#endif
    int x = 66;
    int y = 182;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0 + custom_ui_index, x, y, FILE_IMG_9402_poweroff_text);
    }
    // bool ret = disp_show_localize(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_string_key_power_off_text, temp_index_start + custom_ui_index);
    // if (!ret)
    // {
    //     _disp_show_flash_img(DISP_LFS_FILE_INDEX_0 + custom_ui_index, 76, 177, FILE_IMG_3002_main_text);
    // }
    ++custom_ui_index;
#else
    int x = 58;
    int y = 36;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_9401_poweroff_icon);
    x = 66;
    y = 182;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_9402_poweroff_text);
    }
#endif
    show_button_up();
    show_button_right();
    show_button_down();
}
void view_others_power_off_confirm_display(void)
{
    int x = 13;
    int y = 0;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_9403_poweroff_no);
    x += 89;
    y += 29;
    if (disp_ctrl.com_data.uint8_temp[50])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[51]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_3, x, y, FILE_IMG_9403_poweroff_no_89_29);
    }
    x = 13;
    y = 174;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_9404_poweroff_yes);
    x += 84;
    y += 24;
    if (disp_ctrl.com_data.uint8_temp[150])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[151]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_4, x, y, FILE_IMG_9404_poweroff_yes_84_24);
    }
    x = 66;
    y = 114;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_9402_poweroff_text);
    }
}

int32_t view_others_display(int32_t view)
{
    Expects(view >= view_others);
    Expects(view < view_others + VIEW_LEVEL_0_SUB_COUNT);
    switch (view)
    {
    case view_others_base:
        view_others_base_display();
        break;
    case view_others_camera:
        view_others_camera_display();
        break;
    case view_others_stopwatch:
        view_others_stopwatch_display();
        break;
    case view_others_device_info:
        view_others_device_info_display();
        break;
    case view_others_power_off:
        view_others_power_off_display();
        break;
    case view_others_camera_static:
        //#warning todo ble断开，显示断开图标
        // BraceletSendToAPPCamera(CAMERA_CMD_SLAVE_LEVECAMERA); 離開view
        view_others_camera_static_display();
        break;
    case view_others_camera_shake:
        view_others_camera_shake_display();
        break;
    case view_others_stopwatch_state:
        view_others_stopwatch_state_display();
        break;
    case view_others_device_info_detail:
        view_others_device_info_detail_display();
        break;
    case view_others_power_off_confirm:
        view_others_power_off_confirm_display();
        break;
    case view_others_app_url:
        view_others_app_url_display();
        break;
    }
    return 0;
}
view_event_result_t view_others_power_off_event(event_param_t param)
{
    switch (param.event)
    {
    case event_move_previous_view:
        display_show(view_others_power_off, DISP_MODE_NORMAL);
        return view_event_result_handled;
    case event_move_next_view:
        motor_start(500);
        system_into_poweroff(); //关机
        return view_event_result_handled;
    case BUTTON_EVENT_TP_TAP:
        if (param.y <= 120)
        {
            display_show(view_others_power_off, DISP_MODE_NORMAL);
        }
        else
        {
            motor_start(500);
            system_into_poweroff(); //关机
        }
        return view_event_result_handled;
    }
    return view_event_result_not_handled;
}
view_event_result_t view_others_event(int32_t view, event_param_t param)
{
    Expects(view >= view_others);
    Expects(view < view_others + VIEW_LEVEL_0_SUB_COUNT);
    view_event_result_t result = view_event_result_not_handled;
    switch (view)
    {
    case view_others_stopwatch_state:
        result = view_others_stopwatch_state_event(param);
        break;
    case view_others_power_off_confirm:
        result = view_others_power_off_event(param);
        break;
    }
    if (result == view_event_result_handled)
    {
        return result;
    }
    switch (param.source)
    {
    case event_source_system:
    {
        switch (param.event)
        {
        case event_move_previous_view:
        {
            switch (view)
            {
            case view_others_level_1_begin:
                display_show(view_others_level_1_end - VIEW_LEVEL_1_SUB_COUNT, DISP_MODE_UP_MOVE);
                return view_event_result_handled;
            }
            break;
        }
        case event_move_next_view:
        {
            switch (view)
            {
            case (view_others_level_1_end - VIEW_LEVEL_1_SUB_COUNT):
                display_show(view_others_level_1_begin, DISP_MODE_DOWN_MOVE);
                return view_event_result_handled;
            case view_others_camera_static:
            case view_others_device_info_detail:
                return view_event_result_handled;
            }
            break;
        }
        case event_move_level_down:
        {
            switch (view)
            {
            case view_others_camera:
                if (ble_if_connected())
                {
                    display_show(view_prompt_camera_ready, DISP_MODE_NORMAL);
                    BraceletSendToAPPCamera(CAMERA_CMD_SLAVE_INTOCAMERA);
                }
                else
                {
                    display_show(view_prompt_not_connect, DISP_MODE_NORMAL);
                };
                return view_event_result_handled;
            case view_others_app_url:
                return view_event_result_handled;
            }
            break;
        }
        case event_view_entry:
        {
            switch (view)
            {
            case view_others_stopwatch:
            {
                uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
                uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Stopwatch, buff, buff_len);
                return view_event_result_handled;
            }
            case view_others_base:
            {
                uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
                uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Other, buff, buff_len);
                return view_event_result_handled;
            }
            case view_others_camera:
            {
                uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
                uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Camera, buff, buff_len);
                return view_event_result_handled;
            }
            case view_others_camera_shake:
            {
                uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
                uint32_t buff_len = &disp_ctrl.com_data.uint8_temp[150] - buff;
                disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Shake, buff, buff_len);
                buff = &disp_ctrl.com_data.uint8_temp[151];
                buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_Not_Connected, buff, buff_len);
                return view_event_result_handled;
            }
            case view_others_camera_static:
            {
                uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
                uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Shake, buff, buff_len);
                buff = &disp_ctrl.com_data.uint8_temp[151];
                buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_Not_Connected, buff, buff_len);
                return view_event_result_handled;
            }
            case view_others_power_off:
            {
                uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
                uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Power_off, buff, buff_len);
                return view_event_result_handled;
            }
            case view_others_power_off_confirm:
            {
                uint8_t *buff = &disp_ctrl.com_data.uint8_temp[51];
                uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[50] = get_language_text(language_text_index_NO, buff, buff_len);
                buff = &disp_ctrl.com_data.uint8_temp[101];
                buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Power_off, buff, buff_len);
                buff = &disp_ctrl.com_data.uint8_temp[151];
                buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_YES, buff, buff_len);
                return view_event_result_handled;
            }
            case view_others_app_url:
            {
                uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
                uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
                disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_App_Download, buff, buff_len);
                return view_event_result_handled;
            }
            }
            break;
        }
        case event_view_exit:
        {
            switch (view)
            {
            case view_others_camera_static:
            {
                LOG("exit view_others_camera_static");
                if (param.next_view != view_others_camera_shake)
                {
                    BraceletSendToAPPCamera(CAMERA_CMD_SLAVE_LEVECAMERA);
                    sports_mode_state_t state = (sports_mode_state_t)sports_mode_get_state();
                    switch (state)
                    {
                    case sports_mode_state_pause:
                        display_show(view_sports_paused, DISP_MODE_NORMAL);
                        return view_event_result_handled;
                    case sports_mode_state_normal:
                        display_show(view_sports_state_0, DISP_MODE_NORMAL);
                        return view_event_result_handled;
                    }
                }
                break;
            }
            case view_others_camera_shake:
                LOG("exit view_others_camera_shake");
                if (param.next_view != view_others_camera_static)
                {
                    BraceletSendToAPPCamera(CAMERA_CMD_SLAVE_LEVECAMERA);
                    sports_mode_state_t state = (sports_mode_state_t)sports_mode_get_state();
                    switch (state)
                    {
                    case sports_mode_state_pause:
                        display_show(view_sports_paused, DISP_MODE_NORMAL);
                        return view_event_result_handled;
                    case sports_mode_state_normal:
                        display_show(view_sports_state_0, DISP_MODE_NORMAL);
                        return view_event_result_handled;
                    }
                }
                break;
            }
            break;
        }
        }
    }
    break;
    case event_source_gsensor:
    {
        if (param.event == event_shake)
        {
            switch (view)
            {
            case view_others_camera_static:
                if (ble_if_connected())
                {
                    BraceletSendToAPPCamera(CAMERA_CMD_SLAVE_STARTPHOTO);
                    motor_start_extend(MOTOR_VIBRATE_TYPE_SHARK);
                    display_show(view_others_camera_shake, DISP_MODE_NORMAL);
                }
                else
                {
                    //#warning TODO:
                    //未连接
                }
                return view_event_result_handled;
            case view_others_camera_shake:
                disp_ctrl.auto_refresh_count = 0;
                if (ble_if_connected())
                {
                    BraceletSendToAPPCamera(CAMERA_CMD_SLAVE_STARTPHOTO);
                    motor_start_extend(MOTOR_VIBRATE_TYPE_SHARK);
                }
                return view_event_result_handled;
            }
        }
    }
    }
    return view_event_result_not_handled;
}
